//////////////////////////////////////////////////
// STUDENT RESEARCH PROJECT						//
// UNIVERSITY OF HAGEN 2012						//
// File:	WeatherDataProcessor.h				//
// Date:	01.09.2012							//
// Author:	Max Pejs							//
//////////////////////////////////////////////////

#ifndef _WEATHER_DATA_PROCESSOR_H_
#define _WEATHER_DATA_PROCESSOR_H_

#include "typedef.h"
#include "defines.h"
#include "macro.h"
#include "Message.h"
#include "Statistic.h"

#ifndef WIN32
#include "Arduino.h"
#endif

#define SOF_VALUE 0x04

#define SOF_BIT_LENGTH 5
#define WIND_DIR_BIT_LENGTH 4
#define WIND_SPEED_FIELD_LENGTH 12
#define CHECKSUM_FIELD_LENGTH 4

struct WeatherDataSet
{
	UInt8  WindDirection;
	UInt16  WindSpeed;
	UInt8  CheckSum;
	UInt8  InvWindDirection;
	UInt16 InvWindSpeed;
};

enum eState
{ 
	SOF,
	DATA,
	CHECKSUM,
	DATA_INV
};

class WeatherDataProcessor
{
private:
	eState state;
	struct WeatherDataSet recvDataSet;
	struct WeatherDataSet lastCorrectRecvDataSet;
	int tempStorage;
	UInt8 bitCnt;
	unsigned long sendDataLastTimerCnt;

	UInt8 FrameIsOk(void);
	void SendData(WeatherDataSet);
	void WriteDirectionToBuffer(UInt16 windDir, UInt8 * dirPtr);

public:
	WeatherDataProcessor();
	virtual ~WeatherDataProcessor();
	void ProcessBit(UInt8 newBit);
	
	//////////////////////////////////////////////////////////
	//	Checks if the time given by TRANSMISSION_DELAY		//
	//	gone since last transmitionis. If true, transmit	//
	//	data agnain											//			
	//////////////////////////////////////////////////////////
	void SendData(void);
};
#endif	// _WEATHER_DATA_PROCESSOR_H_